import React, { FC, useEffect, useState } from 'react'
import { Card } from 'antd'
import { useTranslation } from 'react-i18next'
import { getCategory } from '@/api/article'
import { Link } from 'react-router-dom'
import style from './search.module.scss'

const Category: FC = () => {
  const [category, setCategory] = useState([])
  useEffect(() => {
    getCategory()
      .then(({ data }) => {
        console.log(data)
        setCategory(data.data)
      })
      .catch((err) => {
        console.log(err)
      })
  }, [])
  const { t } = useTranslation()
  return (
    <div>
      <div className="mb10">
        <Card
          className={style.card}
          size="small"
          title={<p>{t('recommend')}</p>}
        >
          {category.map((item: any) => {
            return (
              <p key={item.id}>
                <Link to={'/ressd'}>
                  <span>{item.label}</span>
                  <span className="fr">
                    {t('total')} {item.articleCount} {t('count')}
                  </span>
                </Link>
              </p>
            )
          })}
        </Card>
      </div>
    </div>
  )
}

export default Category
